// API基础配置
const BASE_URL = 'http://127.0.0.1:8000/uniapp/api'

// 封装请求方法
export const request = (options) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: BASE_URL + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: {
        'Content-Type': 'application/json',
        // 如果需要token认证
        // 'Authorization': 'Bearer ' + uni.getStorageSync('token')
        ...options.header
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data)
        } else {
          reject(new Error(`请求失败: ${res.statusCode}`))
        }
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

// 商品相关API
export const productAPI = {
  // 获取商品列表
  getProductList: (params) => {
    return request({
      url: '/products',
      method: 'GET',
      data: params
    })
  }
} 